package g;

import com.huawei.hms.analytics.core.crypto.AesCipher.AesLen;
import com.pgl.sys.ces.out.ISdkLite;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.charset.Charset;
import java.util.Objects;
import javax.annotation.Nullable;

/* compiled from: Buffer */
public final class e implements g, f, Cloneable, ByteChannel {
    public static final byte[] c = new byte[]{(byte) 48, (byte) 49, (byte) 50, (byte) 51, (byte) 52, (byte) 53, (byte) 54, (byte) 55, (byte) 56, (byte) 57, (byte) 97, (byte) 98, (byte) 99, (byte) 100, (byte) 101, (byte) 102};
    @Nullable
    public v a;
    public long b;

    /* compiled from: Buffer */
    public class a extends InputStream {
        public int available() {
            return (int) Math.min(e.this.b, 2147483647L);
        }

        public void close() {
        }

        public int read() {
            e eVar = e.this;
            return eVar.b > 0 ? eVar.q0() & ISdkLite.REGION_UNSET : -1;
        }

        public String toString() {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(e.this);
            stringBuilder.append(".inputStream()");
            return stringBuilder.toString();
        }

        public int read(byte[] bArr, int i, int i2) {
            return e.this.u(bArr, i, i2);
        }
    }

    public e A() {
        return this;
    }

    public e A0(byte[] bArr, int i, int i2) {
        if (bArr != null) {
            long j = (long) i2;
            b0.b((long) bArr.length, (long) i, j);
            i2 += i;
            while (i < i2) {
                v x0 = x0(1);
                int min = Math.min(i2 - i, 8192 - x0.c);
                System.arraycopy(bArr, i, x0.a, x0.c, min);
                i += min;
                x0.c += min;
            }
            this.b += j;
            return this;
        }
        throw new IllegalArgumentException("source == null");
    }

    public a0 B() {
        return a0.d;
    }

    public e B0(int i) {
        v x0 = x0(1);
        byte[] bArr = x0.a;
        int i2 = x0.c;
        x0.c = i2 + 1;
        bArr[i2] = (byte) i;
        this.b++;
        return this;
    }

    public /* bridge */ /* synthetic */ f C(byte[] bArr, int i, int i2) throws IOException {
        A0(bArr, i, i2);
        return this;
    }

    /* renamed from: C0 */
    public e k0(long j) {
        int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
        if (i == 0) {
            B0(48);
            return this;
        }
        Object obj = null;
        int i2 = 1;
        if (i < 0) {
            j = -j;
            if (j < 0) {
                G0("-9223372036854775808");
                return this;
            }
            obj = 1;
        }
        if (j >= 100000000) {
            i2 = j < 1000000000000L ? j < 10000000000L ? j < 1000000000 ? 9 : 10 : j < 100000000000L ? 11 : 12 : j < 1000000000000000L ? j < 10000000000000L ? 13 : j < 100000000000000L ? 14 : 15 : j < 100000000000000000L ? j < 10000000000000000L ? 16 : 17 : j < 1000000000000000000L ? 18 : 19;
        } else if (j >= 10000) {
            i2 = j < 1000000 ? j < 100000 ? 5 : 6 : j < 10000000 ? 7 : 8;
        } else if (j >= 100) {
            i2 = j < 1000 ? 3 : 4;
        } else if (j >= 10) {
            i2 = 2;
        }
        if (obj != null) {
            i2++;
        }
        v x0 = x0(i2);
        byte[] bArr = x0.a;
        int i3 = x0.c + i2;
        while (j != 0) {
            i3--;
            bArr[i3] = c[(int) (j % 10)];
            j /= 10;
        }
        if (obj != null) {
            bArr[i3 - 1] = (byte) 45;
        }
        x0.c += i2;
        this.b += (long) i2;
        return this;
    }

    /* renamed from: D0 */
    public e H(long j) {
        if (j == 0) {
            B0(48);
            return this;
        }
        int numberOfTrailingZeros = (Long.numberOfTrailingZeros(Long.highestOneBit(j)) / 4) + 1;
        v x0 = x0(numberOfTrailingZeros);
        byte[] bArr = x0.a;
        int i = x0.c;
        for (int i2 = (i + numberOfTrailingZeros) - 1; i2 >= i; i2--) {
            bArr[i2] = c[(int) (15 & j)];
            j >>>= 4;
        }
        x0.c += numberOfTrailingZeros;
        this.b += (long) numberOfTrailingZeros;
        return this;
    }

    public void E(e eVar, long j) {
        if (eVar == null) {
            throw new IllegalArgumentException("source == null");
        } else if (eVar != this) {
            b0.b(eVar.b, 0, j);
            while (j > 0) {
                v vVar = eVar.a;
                int i = 0;
                if (j < ((long) (vVar.c - vVar.b))) {
                    v vVar2 = this.a;
                    vVar2 = vVar2 != null ? vVar2.g : null;
                    if (vVar2 != null && vVar2.e) {
                        int i2;
                        long j2 = ((long) vVar2.c) + j;
                        if (vVar2.d) {
                            i2 = 0;
                        } else {
                            i2 = vVar2.b;
                        }
                        if (j2 - ((long) i2) <= 8192) {
                            vVar.d(vVar2, (int) j);
                            eVar.b -= j;
                            this.b += j;
                            return;
                        }
                    }
                    int i3 = (int) j;
                    Objects.requireNonNull(vVar);
                    if (i3 <= 0 || i3 > vVar.c - vVar.b) {
                        throw new IllegalArgumentException();
                    }
                    v c;
                    if (i3 >= 1024) {
                        c = vVar.c();
                    } else {
                        c = w.b();
                        System.arraycopy(vVar.a, vVar.b, c.a, 0, i3);
                    }
                    c.c = c.b + i3;
                    vVar.b += i3;
                    vVar.g.b(c);
                    eVar.a = c;
                }
                vVar = eVar.a;
                long j3 = (long) (vVar.c - vVar.b);
                eVar.a = vVar.a();
                v vVar3 = this.a;
                if (vVar3 == null) {
                    this.a = vVar;
                    vVar.g = vVar;
                    vVar.f = vVar;
                } else {
                    vVar3.g.b(vVar);
                    vVar3 = vVar.g;
                    if (vVar3 == vVar) {
                        throw new IllegalStateException();
                    } else if (vVar3.e) {
                        int i4 = vVar.c - vVar.b;
                        int i5 = 8192 - vVar3.c;
                        if (!vVar3.d) {
                            i = vVar3.b;
                        }
                        if (i4 <= i5 + i) {
                            vVar.d(vVar3, i4);
                            vVar.a();
                            w.a(vVar);
                        }
                    }
                }
                eVar.b -= j3;
                this.b += j3;
                j -= j3;
            }
        } else {
            throw new IllegalArgumentException("source == this");
        }
    }

    public e E0(int i) {
        v x0 = x0(4);
        byte[] bArr = x0.a;
        int i2 = x0.c;
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((i >>> 24) & ISdkLite.REGION_UNSET);
        i2 = i3 + 1;
        bArr[i3] = (byte) ((i >>> 16) & ISdkLite.REGION_UNSET);
        i3 = i2 + 1;
        bArr[i2] = (byte) ((i >>> 8) & ISdkLite.REGION_UNSET);
        i2 = i3 + 1;
        bArr[i3] = (byte) (i & ISdkLite.REGION_UNSET);
        x0.c = i2;
        this.b += 4;
        return this;
    }

    public e F0(int i) {
        v x0 = x0(2);
        byte[] bArr = x0.a;
        int i2 = x0.c;
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((i >>> 8) & ISdkLite.REGION_UNSET);
        i2 = i3 + 1;
        bArr[i3] = (byte) (i & ISdkLite.REGION_UNSET);
        x0.c = i2;
        this.b += 2;
        return this;
    }

    public long G(z zVar) throws IOException {
        if (zVar != null) {
            long j = 0;
            while (true) {
                long c = zVar.c(this, 8192);
                if (c == -1) {
                    return j;
                }
                j += c;
            }
        } else {
            throw new IllegalArgumentException("source == null");
        }
    }

    public e G0(String str) {
        H0(str, 0, str.length());
        return this;
    }

    public e H0(String str, int i, int i2) {
        if (str == null) {
            throw new IllegalArgumentException("string == null");
        } else if (i < 0) {
            throw new IllegalArgumentException(c.b.a.a.a.A("beginIndex < 0: ", i));
        } else if (i2 < i) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("endIndex < beginIndex: ");
            stringBuilder.append(i2);
            stringBuilder.append(" < ");
            stringBuilder.append(i);
            throw new IllegalArgumentException(stringBuilder.toString());
        } else if (i2 <= str.length()) {
            while (i < i2) {
                char charAt = str.charAt(i);
                int i3;
                int min;
                int i4;
                if (charAt < 128) {
                    v x0 = x0(1);
                    byte[] bArr = x0.a;
                    i3 = x0.c - i;
                    min = Math.min(i2, 8192 - i3);
                    int i5 = i + 1;
                    bArr[i + i3] = (byte) charAt;
                    while (true) {
                        i = i5;
                        if (i >= min) {
                            break;
                        }
                        charAt = str.charAt(i);
                        if (charAt >= 128) {
                            break;
                        }
                        i5 = i + 1;
                        bArr[i + i3] = (byte) charAt;
                    }
                    i3 += i;
                    i4 = x0.c;
                    i3 -= i4;
                    x0.c = i4 + i3;
                    this.b += (long) i3;
                } else {
                    if (charAt < 2048) {
                        B0((charAt >> 6) | 192);
                        B0((charAt & 63) | AesLen.ROOTKEY_COMPONET_LEN);
                    } else if (charAt < 55296 || charAt > 57343) {
                        B0((charAt >> 12) | 224);
                        B0(((charAt >> 6) & 63) | AesLen.ROOTKEY_COMPONET_LEN);
                        B0((charAt & 63) | AesLen.ROOTKEY_COMPONET_LEN);
                    } else {
                        i3 = i + 1;
                        min = i3 < i2 ? str.charAt(i3) : 0;
                        if (charAt > 56319 || min < 56320 || min > 57343) {
                            B0(63);
                            i = i3;
                        } else {
                            i4 = (((charAt & -55297) << 10) | (-56321 & min)) + 65536;
                            B0((i4 >> 18) | 240);
                            B0(((i4 >> 12) & 63) | AesLen.ROOTKEY_COMPONET_LEN);
                            B0(((i4 >> 6) & 63) | AesLen.ROOTKEY_COMPONET_LEN);
                            B0((i4 & 63) | AesLen.ROOTKEY_COMPONET_LEN);
                            i += 2;
                        }
                    }
                    i++;
                }
            }
            return this;
        } else {
            StringBuilder h = c.b.a.a.a.h("endIndex > string.length: ", i2, " > ");
            h.append(str.length());
            throw new IllegalArgumentException(h.toString());
        }
    }

    public /* bridge */ /* synthetic */ f I(int i) throws IOException {
        F0(i);
        return this;
    }

    public e I0(int i) {
        if (i < AesLen.ROOTKEY_COMPONET_LEN) {
            B0(i);
        } else if (i < 2048) {
            B0((i >> 6) | 192);
            B0((i & 63) | AesLen.ROOTKEY_COMPONET_LEN);
        } else if (i < 65536) {
            if (i < 55296 || i > 57343) {
                B0((i >> 12) | 224);
                B0(((i >> 6) & 63) | AesLen.ROOTKEY_COMPONET_LEN);
                B0((i & 63) | AesLen.ROOTKEY_COMPONET_LEN);
            } else {
                B0(63);
            }
        } else if (i <= 1114111) {
            B0((i >> 18) | 240);
            B0(((i >> 12) & 63) | AesLen.ROOTKEY_COMPONET_LEN);
            B0(((i >> 6) & 63) | AesLen.ROOTKEY_COMPONET_LEN);
            B0((i & 63) | AesLen.ROOTKEY_COMPONET_LEN);
        } else {
            StringBuilder g = c.b.a.a.a.g("Unexpected code point: ");
            g.append(Integer.toHexString(i));
            throw new IllegalArgumentException(g.toString());
        }
        return this;
    }

    public int J() {
        long j = this.b;
        if (j >= 4) {
            v vVar = this.a;
            int i = vVar.b;
            int i2 = vVar.c;
            if (i2 - i < 4) {
                return ((((q0() & ISdkLite.REGION_UNSET) << 24) | ((q0() & ISdkLite.REGION_UNSET) << 16)) | ((q0() & ISdkLite.REGION_UNSET) << 8)) | (q0() & ISdkLite.REGION_UNSET);
            }
            byte[] bArr = vVar.a;
            int i3 = i + 1;
            int i4 = i3 + 1;
            i = ((bArr[i] & ISdkLite.REGION_UNSET) << 24) | ((bArr[i3] & ISdkLite.REGION_UNSET) << 16);
            i3 = i4 + 1;
            i |= (bArr[i4] & ISdkLite.REGION_UNSET) << 8;
            i4 = i3 + 1;
            i |= bArr[i3] & ISdkLite.REGION_UNSET;
            this.b = j - 4;
            if (i4 == i2) {
                this.a = vVar.a();
                w.a(vVar);
            } else {
                vVar.b = i4;
            }
            return i;
        }
        StringBuilder g = c.b.a.a.a.g("size < 4: ");
        g.append(this.b);
        throw new IllegalStateException(g.toString());
    }

    public /* bridge */ /* synthetic */ f K(int i) throws IOException {
        E0(i);
        return this;
    }

    public String M() throws EOFException {
        return b0(Long.MAX_VALUE);
    }

    public int N() {
        return b0.c(J());
    }

    public f P(int i) throws IOException {
        E0(b0.c(i));
        return this;
    }

    public boolean Q() {
        return this.b == 0;
    }

    public /* bridge */ /* synthetic */ f R(int i) throws IOException {
        B0(i);
        return this;
    }

    public byte[] S(long j) throws EOFException {
        b0.b(this.b, 0, j);
        if (j <= 2147483647L) {
            byte[] bArr = new byte[((int) j)];
            w(bArr);
            return bArr;
        }
        throw new IllegalArgumentException(c.b.a.a.a.B("byteCount > Integer.MAX_VALUE: ", j));
    }

    public /* bridge */ /* synthetic */ f V(byte[] bArr) throws IOException {
        z0(bArr);
        return this;
    }

    public /* bridge */ /* synthetic */ f W(h hVar) throws IOException {
        y0(hVar);
        return this;
    }

    public short X() {
        short c0 = c0();
        Charset charset = b0.a;
        int i = c0 & 65535;
        return (short) (((i & ISdkLite.REGION_UNSET) << 8) | ((65280 & i) >>> 8));
    }

    public long Y(h hVar) {
        return t(hVar, 0);
    }

    public f Z() throws IOException {
        return this;
    }

    public String b0(long j) throws EOFException {
        if (j >= 0) {
            long j2 = Long.MAX_VALUE;
            if (j != Long.MAX_VALUE) {
                j2 = j + 1;
            }
            long s = s((byte) 10, 0, j2);
            if (s != -1) {
                return u0(s);
            }
            if (j2 < this.b && r(j2 - 1) == (byte) 13 && r(j2) == (byte) 10) {
                return u0(j2);
            }
            e eVar = new e();
            o(eVar, 0, Math.min(32, this.b));
            StringBuilder g = c.b.a.a.a.g("\\n not found: limit=");
            g.append(Math.min(this.b, j));
            g.append(" content=");
            g.append(eVar.v().k());
            g.append(8230);
            throw new EOFException(g.toString());
        }
        throw new IllegalArgumentException(c.b.a.a.a.B("limit < 0: ", j));
    }

    public long c(e eVar, long j) {
        if (eVar == null) {
            throw new IllegalArgumentException("sink == null");
        } else if (j >= 0) {
            long j2 = this.b;
            if (j2 == 0) {
                return -1;
            }
            if (j > j2) {
                j = j2;
            }
            eVar.E(this, j);
            return j;
        } else {
            throw new IllegalArgumentException(c.b.a.a.a.B("byteCount < 0: ", j));
        }
    }

    public short c0() {
        long j = this.b;
        if (j >= 2) {
            v vVar = this.a;
            int i = vVar.b;
            int i2 = vVar.c;
            if (i2 - i < 2) {
                return (short) (((q0() & ISdkLite.REGION_UNSET) << 8) | (q0() & ISdkLite.REGION_UNSET));
            }
            byte[] bArr = vVar.a;
            int i3 = i + 1;
            int i4 = i3 + 1;
            i = ((bArr[i] & ISdkLite.REGION_UNSET) << 8) | (bArr[i3] & ISdkLite.REGION_UNSET);
            this.b = j - 2;
            if (i4 == i2) {
                this.a = vVar.a();
                w.a(vVar);
            } else {
                vVar.b = i4;
            }
            return (short) i;
        }
        StringBuilder g = c.b.a.a.a.g("size < 2: ");
        g.append(this.b);
        throw new IllegalStateException(g.toString());
    }

    public Object clone() throws CloneNotSupportedException {
        e eVar = new e();
        if (this.b != 0) {
            v c = this.a.c();
            eVar.a = c;
            c.g = c;
            c.f = c;
            c = this.a;
            while (true) {
                c = c.f;
                if (c == this.a) {
                    break;
                }
                eVar.a.g.b(c.c());
            }
            eVar.b = this.b;
        }
        return eVar;
    }

    public void close() {
    }

    public h d(long j) throws EOFException {
        return new h(S(j));
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof e)) {
            return false;
        }
        e eVar = (e) obj;
        long j = this.b;
        if (j != eVar.b) {
            return false;
        }
        long j2 = 0;
        if (j == 0) {
            return true;
        }
        v vVar = this.a;
        v vVar2 = eVar.a;
        int i = vVar.b;
        int i2 = vVar2.b;
        while (j2 < this.b) {
            long min = (long) Math.min(vVar.c - i, vVar2.c - i2);
            int i3 = 0;
            while (((long) i3) < min) {
                int i4 = i + 1;
                int i5 = i2 + 1;
                if (vVar.a[i] != vVar2.a[i2]) {
                    return false;
                }
                i3++;
                i = i4;
                i2 = i5;
            }
            if (i == vVar.c) {
                vVar = vVar.f;
                i = vVar.b;
            }
            if (i2 == vVar2.c) {
                vVar2 = vVar2.f;
                i2 = vVar2.b;
            }
            j2 += min;
        }
        return true;
    }

    public void f(long j) throws EOFException {
        while (j > 0) {
            v vVar = this.a;
            if (vVar != null) {
                int min = (int) Math.min(j, (long) (vVar.c - vVar.b));
                long j2 = (long) min;
                this.b -= j2;
                j -= j2;
                vVar = this.a;
                int i = vVar.b + min;
                vVar.b = i;
                if (i == vVar.c) {
                    this.a = vVar.a();
                    w.a(vVar);
                }
            } else {
                throw new EOFException();
            }
        }
    }

    public void flush() {
    }

    public String h0(long j, Charset charset) throws EOFException {
        b0.b(this.b, 0, j);
        if (charset == null) {
            throw new IllegalArgumentException("charset == null");
        } else if (j > 2147483647L) {
            throw new IllegalArgumentException(c.b.a.a.a.B("byteCount > Integer.MAX_VALUE: ", j));
        } else if (j == 0) {
            return "";
        } else {
            v vVar = this.a;
            if (((long) vVar.b) + j > ((long) vVar.c)) {
                return new String(S(j), charset);
            }
            String str = new String(vVar.a, vVar.b, (int) j, charset);
            int i = (int) (((long) vVar.b) + j);
            vVar.b = i;
            this.b -= j;
            if (i == vVar.c) {
                this.a = vVar.a();
                w.a(vVar);
            }
            return str;
        }
    }

    public int hashCode() {
        v vVar = this.a;
        if (vVar == null) {
            return 0;
        }
        int i = 1;
        do {
            for (int i2 = vVar.b; i2 < vVar.c; i2++) {
                i = (i * 31) + vVar.a[i2];
            }
            vVar = vVar.f;
        } while (vVar != this.a);
        return i;
    }

    public boolean i(long j) {
        return this.b >= j;
    }

    public void i0(long j) throws EOFException {
        if (this.b < j) {
            throw new EOFException();
        }
    }

    public boolean isOpen() {
        return true;
    }

    public /* bridge */ /* synthetic */ f j0(String str) throws IOException {
        G0(str);
        return this;
    }

    public long l0(byte b) {
        return s(b, 0, Long.MAX_VALUE);
    }

    public boolean m0(long j, h hVar) {
        int p = hVar.p();
        if (j < 0 || p < 0 || this.b - j < ((long) p) || hVar.p() - 0 < p) {
            return false;
        }
        for (int i = 0; i < p; i++) {
            if (r(((long) i) + j) != hVar.j(0 + i)) {
                return false;
            }
        }
        return true;
    }

    public final void n() {
        try {
            f(this.b);
        } catch (EOFException e) {
            throw new AssertionError(e);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:32:0x0093  */
    /* JADX WARNING: Removed duplicated region for block: B:31:0x0089  */
    /* JADX WARNING: Removed duplicated region for block: B:40:0x009b A:{SYNTHETIC, EDGE_INSN: B:40:0x009b->B:36:0x009b ?: BREAK  } */
    /* JADX WARNING: Removed duplicated region for block: B:34:0x0097  */
    public long n0() {
        /*
        r15 = this;
        r0 = r15.b;
        r2 = 0;
        r4 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1));
        if (r4 == 0) goto L_0x00a2;
    L_0x0008:
        r0 = 0;
        r1 = 0;
        r4 = r2;
    L_0x000b:
        r6 = r15.a;
        r7 = r6.a;
        r8 = r6.b;
        r9 = r6.c;
    L_0x0013:
        if (r8 >= r9) goto L_0x0087;
    L_0x0015:
        r10 = r7[r8];
        r11 = 48;
        if (r10 < r11) goto L_0x0022;
    L_0x001b:
        r11 = 57;
        if (r10 > r11) goto L_0x0022;
    L_0x001f:
        r11 = r10 + -48;
        goto L_0x0039;
    L_0x0022:
        r11 = 97;
        if (r10 < r11) goto L_0x002d;
    L_0x0026:
        r11 = 102; // 0x66 float:1.43E-43 double:5.04E-322;
        if (r10 > r11) goto L_0x002d;
    L_0x002a:
        r11 = r10 + -97;
        goto L_0x0037;
    L_0x002d:
        r11 = 65;
        if (r10 < r11) goto L_0x006c;
    L_0x0031:
        r11 = 70;
        if (r10 > r11) goto L_0x006c;
    L_0x0035:
        r11 = r10 + -65;
    L_0x0037:
        r11 = r11 + 10;
    L_0x0039:
        r12 = -1152921504606846976; // 0xf000000000000000 float:0.0 double:-3.105036184601418E231;
        r12 = r12 & r4;
        r14 = (r12 > r2 ? 1 : (r12 == r2 ? 0 : -1));
        if (r14 != 0) goto L_0x0049;
    L_0x0040:
        r10 = 4;
        r4 = r4 << r10;
        r10 = (long) r11;
        r4 = r4 | r10;
        r8 = r8 + 1;
        r0 = r0 + 1;
        goto L_0x0013;
    L_0x0049:
        r0 = new g.e;
        r0.m8403init();
        r0 = r0.H(r4);
        r0.B0(r10);
        r1 = new java.lang.NumberFormatException;
        r2 = "Number too large: ";
        r2 = c.b.a.a.a.g(r2);
        r0 = r0.s0();
        r2.append(r0);
        r0 = r2.toString();
        r1.<init>(r0);
        throw r1;
    L_0x006c:
        if (r0 == 0) goto L_0x0070;
    L_0x006e:
        r1 = 1;
        goto L_0x0087;
    L_0x0070:
        r0 = new java.lang.NumberFormatException;
        r1 = "Expected leading [0-9a-fA-F] character but was 0x";
        r1 = c.b.a.a.a.g(r1);
        r2 = java.lang.Integer.toHexString(r10);
        r1.append(r2);
        r1 = r1.toString();
        r0.<init>(r1);
        throw r0;
    L_0x0087:
        if (r8 != r9) goto L_0x0093;
    L_0x0089:
        r7 = r6.a();
        r15.a = r7;
        g.w.a(r6);
        goto L_0x0095;
    L_0x0093:
        r6.b = r8;
    L_0x0095:
        if (r1 != 0) goto L_0x009b;
    L_0x0097:
        r6 = r15.a;
        if (r6 != 0) goto L_0x000b;
    L_0x009b:
        r1 = r15.b;
        r6 = (long) r0;
        r1 = r1 - r6;
        r15.b = r1;
        return r4;
    L_0x00a2:
        r0 = new java.lang.IllegalStateException;
        r1 = "size == 0";
        r0.<init>(r1);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: g.e.n0():long");
    }

    public final e o(e eVar, long j, long j2) {
        if (eVar != null) {
            b0.b(this.b, j, j2);
            if (j2 == 0) {
                return this;
            }
            eVar.b += j2;
            v vVar = this.a;
            while (true) {
                int i = vVar.c;
                int i2 = vVar.b;
                if (j < ((long) (i - i2))) {
                    break;
                }
                j -= (long) (i - i2);
                vVar = vVar.f;
            }
            while (j2 > 0) {
                v c = vVar.c();
                int i3 = (int) (((long) c.b) + j);
                c.b = i3;
                c.c = Math.min(i3 + ((int) j2), c.c);
                v vVar2 = eVar.a;
                if (vVar2 == null) {
                    c.g = c;
                    c.f = c;
                    eVar.a = c;
                } else {
                    vVar2.g.b(c);
                }
                j2 -= (long) (c.c - c.b);
                vVar = vVar.f;
                j = 0;
            }
            return this;
        }
        throw new IllegalArgumentException("out == null");
    }

    public String o0(Charset charset) {
        try {
            return h0(this.b, charset);
        } catch (EOFException e) {
            throw new AssertionError(e);
        }
    }

    public InputStream p0() {
        return new a();
    }

    public byte q0() {
        long j = this.b;
        if (j != 0) {
            v vVar = this.a;
            int i = vVar.b;
            int i2 = vVar.c;
            int i3 = i + 1;
            byte b = vVar.a[i];
            this.b = j - 1;
            if (i3 == i2) {
                this.a = vVar.a();
                w.a(vVar);
            } else {
                vVar.b = i3;
            }
            return b;
        }
        throw new IllegalStateException("size == 0");
    }

    public final byte r(long j) {
        b0.b(this.b, j, 1);
        long j2 = this.b;
        v vVar;
        int i;
        int i2;
        if (j2 - j > j) {
            vVar = this.a;
            while (true) {
                i = vVar.c;
                i2 = vVar.b;
                long j3 = (long) (i - i2);
                if (j < j3) {
                    return vVar.a[i2 + ((int) j)];
                }
                j -= j3;
                vVar = vVar.f;
            }
        } else {
            j -= j2;
            vVar = this.a;
            do {
                vVar = vVar.g;
                i = vVar.c;
                i2 = vVar.b;
                j += (long) (i - i2);
            } while (j < 0);
            return vVar.a[i2 + ((int) j)];
        }
    }

    public int r0(s sVar) {
        int v0 = v0(sVar, false);
        if (v0 == -1) {
            return -1;
        }
        try {
            f((long) sVar.a[v0].p());
            return v0;
        } catch (EOFException unused) {
            throw new AssertionError();
        }
    }

    public int read(ByteBuffer byteBuffer) throws IOException {
        v vVar = this.a;
        if (vVar == null) {
            return -1;
        }
        int min = Math.min(byteBuffer.remaining(), vVar.c - vVar.b);
        byteBuffer.put(vVar.a, vVar.b, min);
        int i = vVar.b + min;
        vVar.b = i;
        this.b -= (long) min;
        if (i == vVar.c) {
            this.a = vVar.a();
            w.a(vVar);
        }
        return min;
    }

    public long s(byte b, long j, long j2) {
        long j3 = 0;
        if (j < 0 || j2 < j) {
            throw new IllegalArgumentException(String.format("size=%s fromIndex=%s toIndex=%s", new Object[]{Long.valueOf(this.b), Long.valueOf(j), Long.valueOf(j2)}));
        }
        long j4 = this.b;
        long j5 = j2 > j4 ? j4 : j2;
        if (j == j5) {
            return -1;
        }
        v vVar = this.a;
        if (vVar == null) {
            return -1;
        }
        if (j4 - j < j) {
            while (j4 > j) {
                vVar = vVar.g;
                j4 -= (long) (vVar.c - vVar.b);
            }
        } else {
            while (true) {
                j4 = ((long) (vVar.c - vVar.b)) + j3;
                if (j4 >= j) {
                    break;
                }
                vVar = vVar.f;
                j3 = j4;
            }
            j4 = j3;
        }
        j3 = j;
        while (j4 < j5) {
            byte[] bArr = vVar.a;
            int min = (int) Math.min((long) vVar.c, (((long) vVar.b) + j5) - j4);
            for (int i = (int) ((((long) vVar.b) + j3) - j4); i < min; i++) {
                if (bArr[i] == b) {
                    return ((long) (i - vVar.b)) + j4;
                }
            }
            byte b2 = b;
            j4 += (long) (vVar.c - vVar.b);
            vVar = vVar.f;
            j3 = j4;
        }
        return -1;
    }

    public String s0() {
        try {
            return h0(this.b, b0.a);
        } catch (EOFException e) {
            throw new AssertionError(e);
        }
    }

    public long t(h hVar, long j) {
        long j2 = 0;
        if (j >= 0) {
            v vVar = this.a;
            if (vVar == null) {
                return -1;
            }
            int i;
            int i2;
            long j3 = this.b;
            if (j3 - j < j) {
                while (j3 > j) {
                    vVar = vVar.g;
                    j3 -= (long) (vVar.c - vVar.b);
                }
            } else {
                while (true) {
                    j3 = ((long) (vVar.c - vVar.b)) + j2;
                    if (j3 >= j) {
                        break;
                    }
                    vVar = vVar.f;
                    j2 = j3;
                }
                j3 = j2;
            }
            int i3;
            if (hVar.p() == 2) {
                byte j4 = hVar.j(0);
                byte j5 = hVar.j(1);
                while (j3 < this.b) {
                    byte[] bArr = vVar.a;
                    i = (int) ((((long) vVar.b) + j) - j3);
                    i3 = vVar.c;
                    while (i < i3) {
                        byte b = bArr[i];
                        if (b == j4 || b == j5) {
                            i2 = vVar.b;
                        } else {
                            i++;
                        }
                    }
                    j3 += (long) (vVar.c - vVar.b);
                    vVar = vVar.f;
                    j = j3;
                }
                return -1;
            }
            byte[] l = hVar.l();
            while (j3 < this.b) {
                byte[] bArr2 = vVar.a;
                i = (int) ((((long) vVar.b) + j) - j3);
                i3 = vVar.c;
                while (i < i3) {
                    byte b2 = bArr2[i];
                    int length = l.length;
                    int i4 = 0;
                    while (i4 < length) {
                        if (b2 == l[i4]) {
                            i2 = vVar.b;
                        } else {
                            i4++;
                        }
                    }
                    i++;
                }
                j3 += (long) (vVar.c - vVar.b);
                vVar = vVar.f;
                j = j3;
            }
            return -1;
            return ((long) (i - i2)) + j3;
        }
        throw new IllegalArgumentException("fromIndex < 0");
    }

    public String t0(long j) throws EOFException {
        return h0(j, b0.a);
    }

    public String toString() {
        return w0().toString();
    }

    public int u(byte[] bArr, int i, int i2) {
        b0.b((long) bArr.length, (long) i, (long) i2);
        v vVar = this.a;
        if (vVar == null) {
            return -1;
        }
        i2 = Math.min(i2, vVar.c - vVar.b);
        System.arraycopy(vVar.a, vVar.b, bArr, i, i2);
        int i3 = vVar.b + i2;
        vVar.b = i3;
        this.b -= (long) i2;
        if (i3 == vVar.c) {
            this.a = vVar.a();
            w.a(vVar);
        }
        return i2;
    }

    public String u0(long j) throws EOFException {
        String t0;
        if (j > 0) {
            long j2 = j - 1;
            if (r(j2) == (byte) 13) {
                t0 = t0(j2);
                f(2);
                return t0;
            }
        }
        t0 = t0(j);
        f(1);
        return t0;
    }

    public h v() {
        try {
            return new h(S(this.b));
        } catch (EOFException e) {
            throw new AssertionError(e);
        }
    }

    public int v0(s sVar, boolean z) {
        s sVar2 = sVar;
        v vVar = this.a;
        int i = -2;
        if (vVar != null) {
            byte[] bArr = vVar.a;
            int i2 = vVar.b;
            int i3 = vVar.c;
            int[] iArr = sVar2.b;
            v vVar2 = vVar;
            int i4 = 0;
            int i5 = -1;
            loop0:
            while (true) {
                int i6 = i4 + 1;
                i4 = iArr[i4];
                int i7 = i6 + 1;
                i6 = iArr[i6];
                if (i6 != -1) {
                    i5 = i6;
                }
                if (vVar2 == null) {
                    break;
                }
                int i8;
                int i9;
                if (i4 < 0) {
                    i8 = (i4 * -1) + i7;
                    while (true) {
                        i4 = i2 + 1;
                        i9 = i7 + 1;
                        if ((bArr[i2] & ISdkLite.REGION_UNSET) != iArr[i7]) {
                            return i5;
                        }
                        int i10;
                        v vVar3;
                        Object obj = i9 == i8 ? 1 : null;
                        if (i4 == i3) {
                            v vVar4 = vVar2.f;
                            i3 = vVar4.b;
                            byte[] bArr2 = vVar4.a;
                            i10 = vVar4.c;
                            if (vVar4 != vVar) {
                                byte[] bArr3 = bArr2;
                                vVar3 = vVar4;
                                bArr = bArr3;
                            } else if (obj == null) {
                                break loop0;
                            } else {
                                bArr = bArr2;
                                vVar3 = null;
                            }
                        } else {
                            v vVar5 = vVar2;
                            i10 = i3;
                            i3 = i4;
                            vVar3 = vVar5;
                        }
                        if (obj != null) {
                            i2 = iArr[i9];
                            i = i3;
                            i3 = i10;
                            vVar2 = vVar3;
                            break;
                        }
                        i2 = i3;
                        i3 = i10;
                        i7 = i9;
                        vVar2 = vVar3;
                    }
                } else {
                    i8 = i2 + 1;
                    i2 = bArr[i2] & ISdkLite.REGION_UNSET;
                    i9 = i7 + i4;
                    while (i7 != i9) {
                        if (i2 == iArr[i7]) {
                            i2 = iArr[i7 + i4];
                            if (i8 == i3) {
                                vVar2 = vVar2.f;
                                i = vVar2.b;
                                bArr = vVar2.a;
                                i3 = vVar2.c;
                                if (vVar2 == vVar) {
                                    vVar2 = null;
                                }
                            } else {
                                i = i8;
                            }
                        } else {
                            i7++;
                        }
                    }
                    return i5;
                }
                if (i2 >= 0) {
                    return i2;
                }
                i4 = -i2;
                i2 = i;
                i = -2;
            }
            return z ? i : i5;
        } else if (z) {
            return -2;
        } else {
            return sVar2.indexOf(h.e);
        }
    }

    public void w(byte[] bArr) throws EOFException {
        int i = 0;
        while (i < bArr.length) {
            int u = u(bArr, i, bArr.length - i);
            if (u != -1) {
                i += u;
            } else {
                throw new EOFException();
            }
        }
    }

    public final h w0() {
        long j = this.b;
        if (j <= 2147483647L) {
            int i = (int) j;
            if (i == 0) {
                return h.e;
            }
            return new x(this, i);
        }
        StringBuilder g = c.b.a.a.a.g("size > Integer.MAX_VALUE: ");
        g.append(this.b);
        throw new IllegalArgumentException(g.toString());
    }

    public int write(ByteBuffer byteBuffer) throws IOException {
        if (byteBuffer != null) {
            int remaining = byteBuffer.remaining();
            int i = remaining;
            while (i > 0) {
                v x0 = x0(1);
                int min = Math.min(i, 8192 - x0.c);
                byteBuffer.get(x0.a, x0.c, min);
                i -= min;
                x0.c += min;
            }
            this.b += (long) remaining;
            return remaining;
        }
        throw new IllegalArgumentException("source == null");
    }

    public v x0(int i) {
        if (i < 1 || i > 8192) {
            throw new IllegalArgumentException();
        }
        v vVar = this.a;
        v b;
        if (vVar == null) {
            b = w.b();
            this.a = b;
            b.g = b;
            b.f = b;
            return b;
        }
        vVar = vVar.g;
        if (vVar.c + i > 8192 || !vVar.e) {
            b = w.b();
            vVar.b(b);
            vVar = b;
        }
        return vVar;
    }

    public e y0(h hVar) {
        if (hVar != null) {
            hVar.x(this);
            return this;
        }
        throw new IllegalArgumentException("byteString == null");
    }

    public e z0(byte[] bArr) {
        if (bArr != null) {
            A0(bArr, 0, bArr.length);
            return this;
        }
        throw new IllegalArgumentException("source == null");
    }
}
